package com.zjs.contorller;

import java.util.Random;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestContorller {
	
	int count = 1;

	@GetMapping("/testB")
	public String testB() {
		return randomlyRunLong();
	}

	private String randomlyRunLong() {
		Random rand = new Random();

		int randomNum = rand.nextInt(2) + 1;

		if (randomNum == 2) {
			sleep();
			return "B服务休眠5s";
		}
		return "B服务无休眠";
	}

	private void sleep() {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	
	@GetMapping("/testC")
	public String testC() {
		try {
			Thread.sleep(7000);
			System.out.println("休眠");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "休眠3s"+ count++  +"次";
	}

}
